import { http, longTimeHttp } from '@/api';
import { PORT1 } from '@/api/config/port';
import { EnumsReq, EnumsRes } from '@/api/interface/index';
import { Role } from '../interface/authentication';
import qs from 'qs';

export const Enums = (params: EnumsReq) => {
  return http.get<Array<EnumsRes>>(PORT1 + `/admin/common/enums`, params, {
    cancel: false,
  });
};

export const Emirates = (params = {}) => {
  return http.get<Array<EnumsRes>>(PORT1 + `/admin/entity/emirates`, params, {
    cancel: false,
  });
};

export const Login = (params) => {
  return http.post<{ token: string; menus: Array<any>; roles: Array<Role> }>(
    PORT1 + `/admin/account/login`,
    params
  );
};

export const Profile = (params = {}) => {
  return http.post<{ token: string; menus: Array<any>; roles: Array<Role> }>(
    PORT1 + `/admin/account/profile`,
    params
  );
};

export const LoginOut = () => {
  return http.get<any>(PORT1 + `/admin/account/logout`);
};

// 上传文件
export const UploadFile = (params: any) => {
  return longTimeHttp.post<string>(PORT1 + `/admin/file/upload`, params, {
    loading: false,
    cancel: false,
  });
};

// 预下载，生成临时访问地址
export const FileLink = (
  params: { objectKey: string; fileName: string },
  loading?: boolean
) => {
  console.log(loading);
  return http.get<any>(
    PORT1 + `/admin/file/link?${qs.stringify(params)}`,
    {},
    {
      loading: loading,
      cancel: false,
    }
  );
};
